<?php
/**
 * 使用示例
 * @author M2
 * @version 1.0
 * create Date 2013-11-4
 * <yl:site />
 * <yl:site field="name" />
 */
class YlSiteTaglib {
    public function __construct() {
        C(include SITE_PATH.'/extends/taglib/tagarr.php');
    }
	public function parse($content,$siteid) {
        if (stripos($content, 'yl:site') !== false) {
            $matches = preg_parse($content, 'yl:site');
            foreach ($matches as $match) {
                $sitename = getParseOneAttr($match, 'siteName');
                $field = getParseOneAttr($match, 'field');
                if (!empty($sitename)) {
                    $text = getParseContentText($match, 'yl:site');
                    $findSite = M('cms_site')->where('name="'.$sitename.'"')->find();
                    $siteid = $findSite['siteid'];
                    $changeStyle = model('Data')->get('cmsconfig:site-'.$siteid);
                    $text = taglib(C('yl:channels'))->parse($text,$siteid,$siteid,$findSite['domain'],$changeStyle);
                    $text = taglib(C('yl:contents'))->parse($text,$siteid,$siteid,$findSite['domain'],$changeStyle);
                    $text = taglib(C('yl:a'))->parse($text,$siteid,null,'',$findSite['domain'],$changeStyle);
                    $text = taglib(C('yl:ad'))->parse($text,$siteid);
                } else {
                    $field = empty($field)?'domain':$field;

                    //add next 2013-12-12 增加缓存判断
                    if (($site = S('cache_siteid_'.$siteid)) === false) {
                        $data['siteid'] = $siteid;
                        $site = M('cms_site')->where($data)->find();
                        S('cache_siteid_'.$siteid, $site);
                    }
                    $text = $site[$field];
                }
                $content = str_replace($match, $text, $content);
            }
        }
        return $content;
	}
}